namespace QMVnSoft.SystemForms
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormPriceCalculate : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private IContainer components;
        private GBoxControl gBoxControl1;
        private LabelControl lblMa_Kho;
        private LabelControl lblMa_Vt;
        private LabelControl lblNgay_Ct1;
        private LabelControl lblNgay_Ct2;
        private TextSearch txtMa_Kho;
        private TextSearch txtMa_Vt;
        private TextDate txtNgay_Ct1;
        private TextDate txtNgay_Ct2;
        private TextControl txtTen_Kho;
        private TextControl txtTen_Vt;

        public FormPriceCalculate()
        {
            this.InitializeComponent();
            this.txtNgay_Ct1.Value = AppInstance.StartWorkingDate;
            this.txtNgay_Ct2.Value = AppInstance.EndWorkingDate;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if ((this.txtNgay_Ct1.Value == DBNull.Value) || (this.txtNgay_Ct2.Value == DBNull.Value))
            {
                MessageBox.Show("Chưa nhập ngày tính giá!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if ((((DateTime) this.txtNgay_Ct2.Value) < AppInstance.OpeningDateOfSubEnterprice) || (((DateTime) this.txtNgay_Ct2.Value) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                this.Calculate();
            }
        }

        private void Calculate()
        {
            if ((this.txtNgay_Ct1.Value == DBNull.Value) || (this.txtNgay_Ct2.Value == DBNull.Value))
            {
                MessageBox.Show("Chưa nhập ngày để tính giá xuất kho!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (((DateTime) this.txtNgay_Ct1.Value) > ((DateTime) this.txtNgay_Ct2.Value))
            {
                MessageBox.Show("Ngày bắt đầu không được lớn hơn ngày kết thúc!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (((DateTime) this.txtNgay_Ct1.Value) < AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Ngày phải bắt đầu từ " + AppInstance.OpeningDateOfSubEnterprice.ToShortDateString() + "!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                AppInstance.StartWorkingDate = (DateTime) this.txtNgay_Ct1.Value;
                AppInstance.EndWorkingDate = (DateTime) this.txtNgay_Ct2.Value;
                PriceCalculateDataAccess access = new PriceCalculateDataAccess();
                if (AppInstance.CostingMethod == 0)
                {
                    access.Calculate0(AppInstance.Subsidiary, this.txtNgay_Ct1.Value, this.txtNgay_Ct2.Value, this.txtMa_Kho.Value, this.txtMa_Vt.Value);
                }
                else if (AppInstance.CostingMethod == 1)
                {
                    access.Calculate1(AppInstance.Subsidiary, this.txtNgay_Ct1.Value, this.txtNgay_Ct2.Value, this.txtMa_Kho.Value, this.txtMa_Vt.Value);
                }
                else if (AppInstance.CostingMethod == 2)
                {
                    access.Calculate2(AppInstance.Subsidiary, this.txtNgay_Ct1.Value, this.txtNgay_Ct2.Value, this.txtMa_Kho.Value, this.txtMa_Vt.Value);
                }

                MessageBox.Show(AppInstance.EndMessage, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                base.Close();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPriceCalculate));
            this.txtNgay_Ct2 = new QMVnSoft.Controls.TextDate();
            this.lblNgay_Ct2 = new QMVnSoft.Controls.LabelControl();
            this.txtNgay_Ct1 = new QMVnSoft.Controls.TextDate();
            this.lblNgay_Ct1 = new QMVnSoft.Controls.LabelControl();
            this.btnCancel = new QMVnSoft.Controls.BtnControl();
            this.btnOk = new QMVnSoft.Controls.BtnControl();
            this.gBoxControl1 = new QMVnSoft.Controls.GBoxControl();
            this.txtTen_Kho = new QMVnSoft.Controls.TextControl();
            this.txtMa_Kho = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Kho = new QMVnSoft.Controls.LabelControl();
            this.txtTen_Vt = new QMVnSoft.Controls.TextControl();
            this.txtMa_Vt = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Vt = new QMVnSoft.Controls.LabelControl();
            this.gBoxControl1.SuspendLayout();
            this.SuspendLayout();
            // 
            // txtNgay_Ct2
            // 
            this.txtNgay_Ct2.DateTimeFormat = QMVnSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ct2.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ct2.Location = new System.Drawing.Point(282, 36);
            this.txtNgay_Ct2.Mask = "00/00/0000";
            this.txtNgay_Ct2.Name = "txtNgay_Ct2";
            this.txtNgay_Ct2.OldValue = null;
            this.txtNgay_Ct2.Size = new System.Drawing.Size(100, 20);
            this.txtNgay_Ct2.TabIndex = 1;
            this.txtNgay_Ct2.Value = ((object)(resources.GetObject("txtNgay_Ct2.Value")));
            // 
            // lblNgay_Ct2
            // 
            this.lblNgay_Ct2.AutoSize = true;
            this.lblNgay_Ct2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Ct2.Location = new System.Drawing.Point(222, 39);
            this.lblNgay_Ct2.Name = "lblNgay_Ct2";
            this.lblNgay_Ct2.Size = new System.Drawing.Size(54, 14);
            this.lblNgay_Ct2.TabIndex = 4;
            this.lblNgay_Ct2.Text = "Đến ngày";
            // 
            // txtNgay_Ct1
            // 
            this.txtNgay_Ct1.DateTimeFormat = QMVnSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ct1.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ct1.Location = new System.Drawing.Point(90, 36);
            this.txtNgay_Ct1.Mask = "00/00/0000";
            this.txtNgay_Ct1.Name = "txtNgay_Ct1";
            this.txtNgay_Ct1.OldValue = null;
            this.txtNgay_Ct1.Size = new System.Drawing.Size(100, 20);
            this.txtNgay_Ct1.TabIndex = 0;
            this.txtNgay_Ct1.Value = ((object)(resources.GetObject("txtNgay_Ct1.Value")));
            // 
            // lblNgay_Ct1
            // 
            this.lblNgay_Ct1.AutoSize = true;
            this.lblNgay_Ct1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Ct1.Location = new System.Drawing.Point(13, 39);
            this.lblNgay_Ct1.Name = "lblNgay_Ct1";
            this.lblNgay_Ct1.Size = new System.Drawing.Size(47, 14);
            this.lblNgay_Ct1.TabIndex = 3;
            this.lblNgay_Ct1.Text = "Từ ngày";
            // 
            // btnCancel
            // 
            this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnCancel.Location = new System.Drawing.Point(315, 158);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(94, 23);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "&Huỷ bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnOk
            // 
            this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnOk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnOk.Location = new System.Drawing.Point(215, 158);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(94, 23);
            this.btnOk.TabIndex = 1;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
            // 
            // gBoxControl1
            // 
            this.gBoxControl1.Controls.Add(this.txtTen_Kho);
            this.gBoxControl1.Controls.Add(this.txtMa_Kho);
            this.gBoxControl1.Controls.Add(this.txtNgay_Ct2);
            this.gBoxControl1.Controls.Add(this.lblNgay_Ct2);
            this.gBoxControl1.Controls.Add(this.lblMa_Kho);
            this.gBoxControl1.Controls.Add(this.txtTen_Vt);
            this.gBoxControl1.Controls.Add(this.txtNgay_Ct1);
            this.gBoxControl1.Controls.Add(this.lblNgay_Ct1);
            this.gBoxControl1.Controls.Add(this.txtMa_Vt);
            this.gBoxControl1.Controls.Add(this.lblMa_Vt);
            this.gBoxControl1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl1.Location = new System.Drawing.Point(12, 12);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new System.Drawing.Size(397, 131);
            this.gBoxControl1.TabIndex = 0;
            this.gBoxControl1.TabStop = false;
            // 
            // txtTen_Kho
            // 
            this.txtTen_Kho.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Kho.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Kho.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Kho.CheckTextSearched = false;
            this.txtTen_Kho.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Kho.Enabled = false;
            this.txtTen_Kho.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Kho.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Kho.Location = new System.Drawing.Point(196, 61);
            this.txtTen_Kho.Name = "txtTen_Kho";
            this.txtTen_Kho.OldValue = null;
            this.txtTen_Kho.Size = new System.Drawing.Size(186, 13);
            this.txtTen_Kho.TabIndex = 110;
            this.txtTen_Kho.UserTextLength = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Kho.UserTrimMode = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Kho.Value = ((object)(resources.GetObject("txtTen_Kho.Value")));
            // 
            // txtMa_Kho
            // 
            this.txtMa_Kho.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Kho.CheckTextSearched = false;
            this.txtMa_Kho.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Kho.EmptyIsValid = true;
            this.txtMa_Kho.FieldDisplay = "Ten_Kho";
            this.txtMa_Kho.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Kho.FoundIsValid = true;
            this.txtMa_Kho.Location = new System.Drawing.Point(90, 58);
            this.txtMa_Kho.MaxLength = 32;
            this.txtMa_Kho.Name = "txtMa_Kho";
            this.txtMa_Kho.OldValue = null;
            this.txtMa_Kho.Size = new System.Drawing.Size(100, 20);
            this.txtMa_Kho.TabIndex = 2;
            this.txtMa_Kho.TableName = "DMKHO";
            this.txtMa_Kho.TextDisplay = this.txtTen_Kho;
            this.txtMa_Kho.UserTextLength = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Kho.UserTrimMode = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Kho.Value = ((object)(resources.GetObject("txtMa_Kho.Value")));
            // 
            // lblMa_Kho
            // 
            this.lblMa_Kho.AutoSize = true;
            this.lblMa_Kho.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Kho.Location = new System.Drawing.Point(13, 61);
            this.lblMa_Kho.Name = "lblMa_Kho";
            this.lblMa_Kho.Size = new System.Drawing.Size(41, 14);
            this.lblMa_Kho.TabIndex = 114;
            this.lblMa_Kho.Text = "Mã kho";
            // 
            // txtTen_Vt
            // 
            this.txtTen_Vt.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Vt.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Vt.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Vt.CheckTextSearched = false;
            this.txtTen_Vt.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Vt.Enabled = false;
            this.txtTen_Vt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Vt.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Vt.Location = new System.Drawing.Point(196, 83);
            this.txtTen_Vt.Name = "txtTen_Vt";
            this.txtTen_Vt.OldValue = null;
            this.txtTen_Vt.Size = new System.Drawing.Size(186, 13);
            this.txtTen_Vt.TabIndex = 112;
            this.txtTen_Vt.UserTextLength = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Vt.UserTrimMode = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Vt.Value = ((object)(resources.GetObject("txtTen_Vt.Value")));
            // 
            // txtMa_Vt
            // 
            this.txtMa_Vt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Vt.CheckTextSearched = false;
            this.txtMa_Vt.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Vt.EmptyIsValid = true;
            this.txtMa_Vt.FieldDisplay = "Ten_Vt";
            this.txtMa_Vt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Vt.FoundIsValid = true;
            this.txtMa_Vt.Location = new System.Drawing.Point(90, 80);
            this.txtMa_Vt.MaxLength = 32;
            this.txtMa_Vt.Name = "txtMa_Vt";
            this.txtMa_Vt.OldValue = null;
            this.txtMa_Vt.Size = new System.Drawing.Size(100, 20);
            this.txtMa_Vt.TabIndex = 3;
            this.txtMa_Vt.TableName = "DMVT";
            this.txtMa_Vt.TextDisplay = this.txtTen_Vt;
            this.txtMa_Vt.UserTextLength = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Vt.UserTrimMode = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Vt.Value = ((object)(resources.GetObject("txtMa_Vt.Value")));
            // 
            // lblMa_Vt
            // 
            this.lblMa_Vt.AutoSize = true;
            this.lblMa_Vt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Vt.Location = new System.Drawing.Point(13, 83);
            this.lblMa_Vt.Name = "lblMa_Vt";
            this.lblMa_Vt.Size = new System.Drawing.Size(52, 14);
            this.lblMa_Vt.TabIndex = 113;
            this.lblMa_Vt.Text = "Mã vật tư";
            // 
            // FormPriceCalculate
            // 
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(421, 193);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.gBoxControl1);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormPriceCalculate";
            this.Text = "Tính giá xuất kho";
            this.gBoxControl1.ResumeLayout(false);
            this.gBoxControl1.PerformLayout();
            this.ResumeLayout(false);

        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.Calculate();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
}

